package com.spzx.cart.api.factory;

import com.spzx.cart.api.RemoteCartService;
import com.spzx.cart.api.domain.CartInfo;
import com.spzx.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Description:
 * RemoteCartService的降级策略
 * @author Yanxinhao on 2024/12/26
 */
@Slf4j
@Component
public class RemoteCartFallbackFactory implements FallbackFactory<RemoteCartService> {
    @Override
    public RemoteCartService create(Throwable cause) {
        /*return source -> {

        };*/
        return new RemoteCartService() {
            @Override
            public R<List<CartInfo>> getCartCheckedList(String source) {
                log.error("获取购物车列表失败:{}", cause.getMessage());
                return R.fail("获取购物车列表失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> updateCartPrice(Long userId ,String source) {
                log.error("更新选中商品最新价格失败:{}", cause.getMessage());
                return R.fail("更新选中商品最新价格失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> deleteCartCheckedList(Long userId,String source) {
                log.error("删除购物车选中商品失败:{}", cause.getMessage());
                return R.fail("删除用户购物车选中数据失败:" + cause.getMessage());
            }
        };
    }
}

